package dao.imp;

import dao.PayrollDatabase;
import domain.Employee;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class GpayrollDatabase implements PayrollDatabase {
    private static Map<Integer, Employee> employeeMap = new HashMap<>();
    private static Map<Integer, Employee>  unionMemberMap = new HashMap<>();

    @Override
    public Employee getEmployee(int empId) {
        return employeeMap.get(empId);
    }

    @Override
    public void addEmployee(Employee employee) {
        employeeMap.put(employee.getId(), employee);
    }

    @Override
    public void clear() {
        employeeMap.clear();
    }

    @Override
    public void deleteEmployeeById(int empid) {
        employeeMap.remove(empid);
    }

    @Override
    public void addUnionMember(int memberId, Employee employee) {
        unionMemberMap.put(memberId, employee);
    }

    @Override
    public Employee getEmployeeByMemberId(int memberId) {
        return unionMemberMap.get(memberId);
    }

    @Override
    public void deleteUnionMember(int memberId) {
        unionMemberMap.remove(memberId);
    }

    @Override
    public List<Employee> getAllEmployees() {
        List<Employee> employees = new ArrayList<>();
        employeeMap.forEach((k,v) -> employees.add(v));
        return employees;
    }
}
